import 'package:flutter/material.dart';
import 'package:wallpaper/components/list_title/my_list_title_model.dart';

class MyListTitle extends StatelessWidget {
  final List<MyListTitleModel> list;
  const MyListTitle({super.key, required this.list});

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Theme.of(context).colorScheme.primaryContainer,
      borderRadius: BorderRadius.circular(10),
      child: Column(
        children: [
          for (int i = 0; i < list.length; i++) ...[
            InkWell(
              borderRadius: i == 0
                  ? const BorderRadius.vertical(top: Radius.circular(10))
                  : i == list.length - 1
                      ? const BorderRadius.vertical(bottom: Radius.circular(10))
                      : BorderRadius.zero,
              onTap: () {
                // 自定义跳转动画
                if (list[i].route != null) {
                  Navigator.push(
                    context,
                    PageRouteBuilder(
                      settings: RouteSettings(name: ''), // 保留路由名称
                      pageBuilder: (_, animation, __) =>
                          list[i].route!, // 替换为你的目标页面
                      transitionsBuilder: (_, animation, __, child) {
                        // 示例：从右向左滑动动画
                        return SlideTransition(
                          position: Tween<Offset>(
                            begin: const Offset(1.0, 0.0),
                            end: Offset.zero,
                          ).animate(CurvedAnimation(
                            parent: animation,
                            curve: Curves.easeInOut,
                          )),
                          child: child,
                        );
                      },
                      transitionDuration:
                          const Duration(milliseconds: 300), // 动画时长
                    ),
                  );
                }
              },
              child: ListTile(
                title: Text(list[i].title),
                leading: list[i].leading,
                trailing: const Icon(Icons.chevron_right_rounded),
                contentPadding: const EdgeInsets.symmetric(horizontal: 16),
              ),
            ),
            if (i != list.length - 1)
              Padding(
                padding: const EdgeInsets.only(left: 16), // 对齐leading图标
                child: Divider(
                  height: 1,
                  thickness: 0.5,
                  endIndent: 16,
                  color: Colors.grey[300],
                ),
              )
          ]
        ],
      ),
    );
  }
}
